<template>
	<view class="context">
		<view class="title">我的地址</view>
		<view class="item" v-for="(item, index) in list" :key="index" @click="sel(item.address)">
			{{ item.address }}
		</view>
		<button class="btn" @click="toadd">添加地址</button>
	</view>
</template>

<script lang="ts" setup>
import { err, get, to } from '@/utils/uniapi';
import { api } from '@/api/store_api';
import { ref } from 'vue';

const mchMemberNo = get('user').mchMemberNo;
const emit = defineEmits(['sel']);
const list = ref<any>([]);
async function getlist() {
	try {
		const res = await api.addressList({ mchMemberNo });
		if (res.respCode === 200) {
			list.value = JSON.parse(res.source);
			console.log(list.value);
		}
	} catch (e) {
		err(e);
	}
}
function sel(address: string) {
	emit('sel', { show: false, address });
}
function toadd() {
	to('/user/Addaddress/Addaddress');
}
getlist();
</script>

<style lang="scss" scoped>
.context {
	width: 100%;
	background-color: #f9f9f9;
	min-height: 400rpx;
	padding: 0 30rpx;
	box-sizing: border-box;
	position: relative;
	.title {
		font-size: 28rpx;
		font-weight: 600;
		margin: 20rpx 0;
	}
	.item {
		width: 690rpx;
		margin: 0 auto;
		background-color: #fff;
		color: #333;
		padding: 20rpx;
		box-sizing: border-box;
		margin-bottom: 10rpx;
		font-size: 24rpx;
	}
	.btn {
		width: 690rpx;
		background-color: #c32136;
		color: #ffffff;
		position: absolute;
		bottom: 10rpx;
		left: 50%;
		transform: translateX(-50%);
	}
}
</style>
